package com.ipet.app.ui.base;


import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.view.View;

import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.util.DialogUtils;
import com.ipet.app.R;
import com.ipet.app.util.ColoredSnackbar;

/**
 * Created by jindongping on 16/3/8.
 */
public abstract class BaseFragment extends Fragment {
    protected void snackShow(View view, @NonNull CharSequence msg) {
        Snackbar.make(view, msg, Snackbar.LENGTH_SHORT).setAction("取消", new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        }).setActionTextColor(DialogUtils.getColor(this.getContext(), R.color.colorPrimary)).show();
    }

    protected void snackErr(View view, @NonNull CharSequence msg) {
        ColoredSnackbar.alert(Snackbar.make(view, msg, Snackbar.LENGTH_SHORT).setAction("取消", new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        })).setActionTextColor(DialogUtils.getColor(this.getContext(), R.color.colorPrimary)).show();
    }

    protected MaterialDialog showLoadingDialog() {
        final MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
                .content(R.string.loading)
                .contentColorRes(R.color.pink_500)
                .widgetColorRes(R.color.pink_500)
                .progress(true, 0).show();
        return dialog;
    }

    protected MaterialDialog showLoadingDialog(String content) {
        final MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
                .title(R.string.loading)
                .contentColorRes(R.color.pink_500)
                .widgetColorRes(R.color.pink_500)
                .content(content)
                .progress(true, 0).show();
        return dialog;
    }

    protected MaterialDialog showLoadingDialogNoTitle(String content) {
        final MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
                .content(content)
                .contentColorRes(R.color.pink_500)
                .widgetColorRes(R.color.pink_500)
                .progress(true, 0).show();
        return dialog;
    }

}
